//
//  EmoticonAttachment.m
//  王雷Sinoweibo
//
//  Created by wanglei on 16/12/13.
//  Copyright © 2016年 wanglei. All rights reserved.
//

#import "EmoticonAttachment.h"

@implementation EmoticonAttachment

//将表情图片转换为属性文本
+ (NSAttributedString *)emoticonImageToImageText:(Emoticon *)em font:(UIFont*)font;{
    EmoticonAttachment *attachment = [[EmoticonAttachment alloc]init];
//    将附件类型添加为图片
    attachment.image = [UIImage imageWithContentsOfFile:em.imagePath];
    attachment.chs = em.chs;
    CGFloat lineHeight = font.lineHeight;
    attachment.bounds = CGRectMake(0, -4, lineHeight, lineHeight);
    NSAttributedString *str = [NSAttributedString attributedStringWithAttachment:attachment];
    NSMutableAttributedString *imageText = [[NSMutableAttributedString alloc]initWithAttributedString:str];
//    给文本添加属性,只有可变的文本才能添加属性
    [imageText addAttribute:NSFontAttributeName value:font range:NSMakeRange(0, 1)];
    return imageText;
}
@end
